package day6;

import day5.Sc;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Student {
    String name;
    String id;
    String major;//专业
    double score;

    public Student(String name, String id, String major, double score) {
        this.name = name;
        this.id = id;
        this.major = major;
        this.score = score;
    }
}
class TestStudent{
    static Integer n=1;//入学顺序
    static Scanner sc=new Scanner(System.in);
    static Map<String,Student> map=new HashMap<>();
    public static void main(String[] args) {
        oneMenu();
    }
    public static void oneMenu(){
        while (true){
            System.out.println("xxx成绩管理系统");
            System.out.println("1.查询");
            System.out.println("2.插入");
            System.out.println("3.删除");
            System.out.println("4.退出");
            int n=sc.nextInt();
            switch (n){
                case 1:select();break;
                case 2:insert();break;
                case 3:delete();break;
            }
        }
    }
    public static void select(){
        System.out.println("学号");
        String no=sc.next();
        for(String key:map.keySet()){
            //模糊查询
            if(key.contains(no)){
                Student stu=map.get(key);
                System.out.println(stu.id+" "+stu.name);
            }
        }
       /*map.entrySet().//获取
               stream()
               .filter((Map.Entry<String,Student> e)
                       ->e.getKey().contains(no))
               .forEach((Map.Entry e)->
                       System.out.println(e.getKey()+" "+e.getValue()));*/
    }
    public static void insert(){
        //System.out.println("请输入学号");
        String id=getNo();
        System.out.println("姓名");
        String name=sc.next();
        System.out.println("专业");
        String major=sc.next();
        System.out.println("成绩");
        double score=sc.nextDouble();
        Student student=new Student(id,name,major,score);
        map.put(id,student);
        System.out.println(name+"插入成功");
    }
    public static String getNo(){//自动生成学号
        StringBuilder sb=new StringBuilder("SC");
       sb.append(n++ +"");
       int length=sb.length();
        if(length<5){
            for(int i=0;i<5-length;i++){
               sb.insert(2,"0");
            }
        }
        System.out.println(sb);
        return sb.toString();
    }
    public static void delete(){
        System.out.println("要删除的");
        String nos=sc.next();
        String[] ids=nos.split(",");
        for(String id1:ids){
            if(map.containsKey(id1)){
                map.remove(id1);
                System.out.println(id1+"学号已删除");
            }
        }
    }
}
